package com.hckj.jianzhijia.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by 赵奇隆 on 2015-11-01.
 */
public class SharedPreferencesUtil {

    private Context context;
    private SharedPreferences sp;


    public SharedPreferencesUtil(Context context) {
        this.context = context;
        this.sp = context.getSharedPreferences("userSetting", context.MODE_PRIVATE);
    }

    public  void setCurrentUserPhone(String phoneNum) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("userPhone", phoneNum);
        editor.commit();
    }

    public  void setCurrentUserPhonePassword(String phoneNum, String password) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("userPhone", phoneNum);
        editor.putString("password", password);
        editor.commit();
    }

    public  String getCurrentUserPhone() {
        return sp.getString("userPhone", "");
    }

    public  String getCurrentUserPassword() {
        return sp.getString("password", "");
    }

    public boolean isAutoLogin() {
        return sp.getBoolean("isAutoLogin", false);
    }

    public void setAutoLogin(boolean isAutoLogin){
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean("isAutoLogin", isAutoLogin);
        editor.commit();
    }

    public void cleanUserInfo(){
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("userPhone", "");
        editor.putString("password", "");
        editor.putBoolean("isAutoLogin", false);
        editor.commit();
    }

    public boolean ifFirstUse(){
        return sp.getBoolean("firstUse", true);
    }

    public void firstUse(){
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean("firstUse", false);
        editor.commit();
    }

    public boolean ifAutoUpdate(){
        return sp.getBoolean("AutoUpdate", true);
    }

    public void setAutoUpdate(boolean autoUpdate){
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean("AutoUpdate", autoUpdate);
        editor.commit();
    }


}
